//
//  YGHomeBLL.m
//  yuanshangyiliao
//
//  Created by icholab on 2021/3/16.
//

#import "YGHomeBLL.h"
#import "CNHTTPManager.h"
#import "UserInfoManager.h"
#import "YGPatientHomeModel.h"
@implementation YGHomeBLL

#pragma -首页接口
+ (void)requestHomeInfoSuccess:(void (^)(YGPatientHomeModel *model))success fail:(void (^)(NSError *error))fail{
    NSString *token = [[UserInfoManager shareInstance] getUserInfo].token;
    NSMutableDictionary *dic = [NSMutableDictionary dictionary];
    [dic setObject:token forKey:@"token"];
    [[CNHTTPManager shared] GET:YG_HOME_URL parameters:dic success:^(id responeObj) {
        NSDictionary *data = [responeObj objectForKey:@"data"];
        YGPatientHomeModel *model = [[YGPatientHomeModel alloc] initWithDictionary:data error:nil];
        if (success) {
            success(model);
        }
    } failure:^(NSError *error, NSString *errorDes) {
        if (fail) {
            fail(error);
        }
    }];
}

#pragma -医院详情接口
+ (void)requestHospitalDetailInfoSuccess:(void (^)(YGHospitalDetailModel *model))success fail:(void (^)(NSError *error))fail{
    
    NSMutableDictionary *dic = [NSMutableDictionary dictionary];
    NSString *hospitalsId = [[UserInfoManager shareInstance] getUserInfo].hospitalsId;
    [dic setObject:hospitalsId forKey:@"hospitalsId"];
    [[CNHTTPManager shared] GET:YG_HOSPITAL_DETAIL_URL parameters:dic success:^(id responeObj) {
            NSDictionary *data = [responeObj objectForKey:@"data"];
            YGHospitalDetailModel *model = [[YGHospitalDetailModel alloc] initWithDictionary:data error:nil];
            if (success) {
                success(model);
            }
        } failure:^(NSError *error, NSString *errorDes) {
            if (fail) {
                fail(error);
            }
        }];
}

#pragma -医生信息接口
+ (void)requestDoctorMessageWithPage:(NSInteger)page rows:(NSInteger)rows Success:(void (^)(YGDoctorMessageModel * _Nonnull,NSInteger totalPage))success fail:(void (^)(NSError * _Nonnull))fail{
    
    NSMutableDictionary *dic = [NSMutableDictionary dictionary];
    [dic fa_setObjectSafe:@(page) forKey:@"page"];
    [dic fa_setObjectSafe:@(20) forKey:@"rows"];
    [[CNHTTPManager shared] GET:YG_DOCTOR_MESSAGE_URL parameters:dic success:^(id responeObj) {
            NSDictionary *data = [responeObj objectForKey:@"data"];
            NSDictionary *doctor =[data objectForKey:@"doctor"];
            NSDictionary *pageData = [data objectForKey:@"pageData"];
            NSInteger totalPage = [[data objectForKey:@"totalPage"] integerValue];
            YGDoctorMessageModel *model = [[YGDoctorMessageModel alloc]initWithDictionary:doctor error:nil];
            if (success) {
                success(model,totalPage);
            }
        } failure:^(NSError *error, NSString *errorDes) {
            if (fail) {
                fail(error);
            }
        }];
}

#pragma -专家列表信息接口
+ (void)requestExpertsListWithPage:(NSInteger)page rows:(NSInteger)rows Success:(void (^)(YGExpertsListModel * _Nonnull,NSInteger totalPage))success fail:(void (^)(NSError * _Nonnull))fail{
    
    NSMutableDictionary *dic = [NSMutableDictionary dictionary];
    [dic fa_setObjectSafe:@(page) forKey:@"page"];
    [dic fa_setObjectSafe:@(20) forKey:@"rows"];
    [[CNHTTPManager shared] GET:YG_EXPERTS_LIST_URL parameters:dic success:^(id responeObj) {
            NSDictionary *data = [responeObj objectForKey:@"data"];
//            NSDictionary *pageData = [data objectForKey:@"pageData"];
            NSInteger totalPage = [[data objectForKey:@"totalPage"] integerValue];
           // NSInteger total = [[data objectForKey:@"total"] integerValue];
            YGExpertsListModel *model = [[YGExpertsListModel alloc]initWithDictionary:data error:nil];
            if (success) {
                success(model,totalPage);
            }
        } failure:^(NSError *error, NSString *errorDes) {
            if (fail) {
                fail(error);
            }
        }];
}

#pragma -营养自助方案-劳动强度字典接口
+ (void)requestOwnHelpLabourStrengthInfoSuccess:(void (^)(NSArray<YGOwnHelpLabourStengthModel *> * _Nonnull))success fail:(void (^)(NSError * _Nonnull))fail{
    
    NSMutableDictionary *dic = [NSMutableDictionary dictionary];
    [[CNHTTPManager shared]GET:YG_OWNHELP_LABOUR_STRENGTH_URL parameters:dic success:^(id responeObj) {
        NSArray *data = [responeObj objectForKey:@"data"];
        NSArray *models = [YGOwnHelpLabourStengthModel arrayOfModelsFromDictionaries:data];
        if (success) {
            success(models);
        }
        } failure:^(NSError *error, NSString *errorDes) {
            if (fail) {
                fail(error);
            }
        }];
}

#pragma 营养自助方案-医院诊断-一级病种接口
+ (void)requestOwnHelpDiseaseInfoSuccess:(void (^)(NSArray<YGOwnHelpDiseaseModel *> * _Nonnull))success fail:(void (^)(NSError * _Nonnull))fail{
    NSMutableDictionary *dic = [NSMutableDictionary dictionary];
    [[CNHTTPManager shared]GET:YG_OWNHELP_DISEASES_TYPE parameters:dic success:^(id responeObj) {
            NSArray *data = [responeObj objectForKey:@"data"];
            NSArray *models = [YGOwnHelpDiseaseModel arrayOfModelsFromDictionaries:data];
            if (success) {
                success(models);
            }
        } failure:^(NSError *error, NSString *errorDes) {
            if (fail) {
                fail(error);
            }
        }];
}

#pragma -营养自助方案-医院诊断-二级病种接口
+ (void)requestOwnHelpDiseaseLowerWithPid:(NSString *)pid Success:(void (^)(NSArray<YGOwnHelpDiseaseLowerModel *> * _Nonnull))success fail:(void (^)(NSError * _Nonnull))fail{
    NSMutableDictionary *dic = [NSMutableDictionary dictionary];
    [dic fa_setObjectSafe:pid forKey:@"pid"];
    [[CNHTTPManager shared]GET:YG_OWNHELP_DISEASES_TYPE_LOWER parameters:dic success:^(id responeObj) {
        NSArray *data = [responeObj objectForKey:@"data"];
        NSArray *models = [YGOwnHelpDiseaseLowerModel arrayOfModelsFromDictionaries:data];
        if (success) {
            success(models);
        }
        } failure:^(NSError *error, NSString *errorDes) {
            if (fail) {
                fail(error);
            }
        }];
}

#pragma -饮食指南一级分类接口
+ (void)requestFoodGuideTypeInfoSuccess:(void (^)(NSArray <YGFoodGuideTypeModel *> *model))success fail:(void (^)(NSError * _Nonnull))fail{
    
    NSMutableDictionary *dic = [NSMutableDictionary dictionary];
    [[CNHTTPManager shared] GET:YG_FOOD_FOODGUIDE_TYPE parameters:dic success:^(id responeObj) {
        NSArray *data = [responeObj objectForKey:@"data"];
        NSArray *models = [YGFoodGuideTypeModel arrayOfModelsFromDictionaries:data];
        if (success) {
            success(models);
        }
        } failure:^(NSError *error, NSString *errorDes) {
            if (fail) {
                fail(error);
            }
        }];
}
#pragma -饮食指南二级分类接口
+ (void)requestFoodGuideLowerWithParentId:(NSString *)parentId Success:(void (^)(NSArray<YGFoodGuideTypeModel *> * _Nonnull))success fail:(void (^)(NSError * _Nonnull))fail{
    
    NSMutableDictionary *dic = [NSMutableDictionary dictionary];
    [dic setObject:parentId forKey:@"parentId"];
    [[CNHTTPManager shared] GET:YG_FOOD_FOODGUIDE_LOWER parameters:dic success:^(id responeObj) {
            NSArray *data = [responeObj objectForKey:@"data"];
            NSArray *models = [YGFoodGuideTypeModel arrayOfModelsFromDictionaries:data];
        if (success) {
            success(models);
        }
        } failure:^(NSError *error, NSString *errorDes) {
            if (fail) {
                fail(error);
            }
        }];
    
}

#pragma -饮食指南内容查询接口
+ (void)requestFoodGuideContentWithTypeId:(NSString *)typeId Success:(void (^)(YGFoodGuideContentModel * _Nonnull))success fail:(void (^)(NSError * _Nonnull))fail{
    NSMutableDictionary *dic = [NSMutableDictionary dictionary];
    [dic setObject:typeId forKey:@"typeId"];
    [[CNHTTPManager shared]GET:YG_FOOD_FOODGUIDE_QUERY_URL parameters:dic success:^(id responeObj) {
            NSDictionary *data =[responeObj objectForKey:@"data"];
        YGFoodGuideContentModel *model = [[YGFoodGuideContentModel alloc]initWithDictionary:data error:nil];
        if (success) {
            success(model);
        }
        } failure:^(NSError *error, NSString *errorDes) {
            if (fail) {
                fail(error);
            }
        }];
}

#pragma -食材百科一级分类接口
+ (void)requestFoodWikipediaTypeInfoSuccess:(void (^)(NSArray<YGFoodWikipediaTypeModel *> * _Nonnull))success fail:(void (^)(NSError * _Nonnull))fail{
    NSMutableDictionary *dic = [NSMutableDictionary dictionary];
    [[CNHTTPManager shared]GET:YG_FOOD_FOODWIKIPEDIA_TYPE parameters:dic success:^(id responeObj) {
            NSArray *data = [responeObj objectForKey:@"data"];
            NSArray *models = [YGFoodWikipediaTypeModel arrayOfModelsFromDictionaries:data];
        if (success) {
            success(models);
        }
        } failure:^(NSError *error, NSString *errorDes) {
            if (fail) {
                fail(error);
            }
        }];
}

#pragma -食材百科-二级分类接口
+(void)requestFoodWikipediaLowerWithParentId:(NSString *)parentId Success:(void (^)(NSArray<YGFoodWikipediaTypeModel *> * _Nonnull))success fail:(void (^)(NSError * _Nonnull))fail{
    NSMutableDictionary *dic = [NSMutableDictionary dictionary];
    [dic setObject:parentId forKey:@"parentId"];
    [[CNHTTPManager shared]GET:YG_FOOD_FOODWIKIPEDIA_LOWER parameters:dic success:^(id responeObj) {
            NSArray *data = [responeObj objectForKey:@"data"];
            NSArray *models = [YGFoodWikipediaTypeModel arrayOfModelsFromDictionaries:data];
        if (success) {
            success(models);
        }
        } failure:^(NSError *error, NSString *errorDes) {
            if (fail) {
                fail(error);
            }
        }];
}

#pragma -食材百科-列表数据接口
+ (void)requestFoodWikipediaTableWithTypeId:(NSString *)typeId page:(NSInteger)page rows:(NSInteger)rows Success:(void (^)(YGFoodWikipediaTableModel * _Nonnull))success fail:(void (^)(NSError * _Nonnull))fail{
    NSMutableDictionary *dic = [NSMutableDictionary dictionary];
    [dic setObject:typeId forKey:@"typeId"];
    [dic fa_setObjectSafe:@(page) forKey:@"page"];
    [dic fa_setObjectSafe:@(rows) forKey:@"rows"];
    [[CNHTTPManager shared]GET:YG_FOOD_FOODWIKIPEDIA_LIST parameters:dic success:^(id responeObj) {
        NSDictionary *data = [responeObj objectForKey:@"data"];
        YGFoodWikipediaTableModel *model = [[YGFoodWikipediaTableModel alloc]initWithDictionary:data error:nil];
        if (success) {
            success(model);
        }
        } failure:^(NSError *error, NSString *errorDes) {
            if (fail) {
                fail(error);
            }
        }];
}

#pragma -食材百科-食材详情接口
+ (void)requestFoodWikipediaContentFoodId:(NSString *)foodId Success:(void (^)(YGFoodWikipediaDetailModel * _Nonnull))success fail:(void (^)(NSError * _Nonnull))fail{
    NSMutableDictionary *dic = [NSMutableDictionary dictionary];
    [dic setObject:foodId forKey:@"foodId"];
    [[CNHTTPManager shared]GET:YG_FOOD_FOODWIKIPEDIA_DETAIL_URL parameters:dic success:^(id responeObj) {
            NSDictionary *data = [responeObj objectForKey:@"data"];
            YGFoodWikipediaDetailModel *model = [[YGFoodWikipediaDetailModel alloc]initWithDictionary:data error:nil];
        if (success) {
            success(model);
        }
        } failure:^(NSError *error, NSString *errorDes) {
            if (fail) {
                fail(error);
            }
        }];
}

#pragma -科普中心-科普中心分类接口
+ (void)requestScienceCenterTypeInfoSuccess:(void (^)(YGScienceCenterTypeModel * _Nonnull))success fail:(void (^)(NSError * _Nonnull))fail{
    NSMutableDictionary *dic = [NSMutableDictionary dictionary];
    [[CNHTTPManager shared]GET:YG_SCIENCE_CENTER_TYPE parameters:dic success:^(id responeObj) {
        NSDictionary *data = [responeObj objectForKey:@"data"];
        YGScienceCenterTypeModel *model = [[YGScienceCenterTypeModel alloc]initWithDictionary:data error:nil];
        if (success) {
            success(model);
        }
        } failure:^(NSError *error, NSString *errorDes) {
            if (fail) {
                fail(error);
            }
        }];
}


@end
